package com.example.demo.LeetCode.list.fastSlow;

import com.example.demo.LeetCode.list.ListNode;

/**
 * 链表是否有环
 */
public class CycleList {
    public boolean hasCycle(ListNode head){
        ListNode fast = head,slow = head;
        while (fast!= null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
            if (fast == slow){
                return true;
            }
        }
        return false;
    }
}
